﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RhinoMockStudy
{
   public class UserBuyProductService
    {
        private Customer customer;

        public Customer Customer
        {
            get { return customer; }
            set { customer = value; }
        }
       private ShoppingCart cart;


       public UserBuyProductService()
       {
           this.customer = new Customer() { ID=1, Age=19, CustomerName="chen", TotalMoney=100};
           this.cart = new ShoppingCart();
           //绑定此购物车是此客户的
           cart.OwnerID = customer.ID;

       }

       /// <summary>
       /// 购买产品
       /// </summary>
       /// <param name="mod_Product"></param>
       public bool Buy(Product mod_Product, int quality)
       {
           var result = false;

           var cartItem = new CartItem { HasBuyInProduct = mod_Product, Quality = quality };
           try
           {
              
               mod_Product.TotalAmount -= quality;
               customer.TotalMoney -= (quality * mod_Product.Price);

               cart.CartItems.Add(cartItem);

               result = true;
           }
           catch (Exception ex)
           {
               
               throw ex;
           }

           return result;
       }

    }
}
